home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 08 Manslow / CProjectile.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-29  |  1.3 KB  |  56 lines

  1. //Tanks
  2. //Copyright John Manslow
  3. //29/09/2001
  4.  
  5. #include "stdafx.h"
  6. #include "CProjectile.h"
  7. #include "math.h"
  8.  
  9. const double dGravity=0.1;
  10. const double dFriction=0.997;
  11.  
  12. CProjectile::CProjectile(const double dNewxPosition,
  13.                          const double dNewyPosition,
  14.                          const double dNewHeadingX,
  15.                          const double dNewHeadingY)
  16. {
  17.     TRACE("\t\tCreating projectile...");
  18.  
  19.     //Record the parameters of the projectile:
  20.     //Its current position,
  21.     dxPosition=dNewxPosition;
  22.     dyPosition=dNewyPosition;
  23.  
  24.     //its position at the end of the previous time step,
  25.     dPreviousxPosition=dxPosition;
  26.     dPreviousyPosition=dyPosition;
  27.  
  28.     //and the x and y components of its velocity.
  29.     dSpeedx=dNewHeadingX;
  30.     dSpeedy=dNewHeadingY;
  31.  
  32.     TRACE("successful.\n");
  33. }
  34.  
  35. CProjectile::~CProjectile()
  36. {
  37.     TRACE("\t\tDestroying projectile...");
  38.     TRACE("successful.\n");
  39. }
  40.  
  41. void CProjectile::TimeStep(const double dWindSpeed)
  42. {
  43.     //Record its current position as its old position
  44.     dPreviousxPosition=dxPosition;
  45.     dPreviousyPosition=dyPosition;
  46.  
  47.     //Update the projectile's position
  48.     dxPosition+=dSpeedx;
  49.     dyPosition+=dSpeedy;
  50.  
  51.     //Update the projectile's velocity. If this model changes, the neural network may have to 
  52.     //be retrained
  53.     dSpeedy-=dGravity;
  54.     dSpeedy*=dFriction;
  55.     dSpeedx+=(dWindSpeed-dSpeedx)*(1.0-dFriction);
  56. }